package com.gdcn.zb.sys.dao.impl;

import java.util.List;
import com.gdcn.zb.base.BaseDao;
import com.gdcn.zb.base.exception.DaoException;
import com.gdcn.zb.sys.dao.IUnitDao;
import com.gdcn.zb.sys.valueobject.Unit;

public class UnitDaoHibernate extends BaseDao implements IUnitDao{

	public void createUnit(Unit unit) throws DaoException {
		super.doCreateObject(unit);
		
	}

	public void deleteUnit(Unit unit) throws DaoException {
		super.doDeleteObject(unit);
		
	}

	public void deleteUnit(int id) throws DaoException {
		super.doDeleteObject(id);
	}

	public Unit findUnitById(int id) throws DaoException {
		return (Unit)super.doFindObjectById(id);
	}

	public void updateUnit(Unit unit) throws DaoException {
		super.doUpdateObject(unit);
		
	}

	protected Class getModelClass() {
		return Unit.class;
	}

	public List listUnitBySekcioId(int sekcioId) throws DaoException {
		List list = this.getHibernateTemplate().find("from Unit unit where unit.sekcio.id="+sekcioId);
		return list;
	}

	public List listUnitByParentIdAndSekcioId(int parentId,int sekcioId) throws DaoException {
		List list = this.getHibernateTemplate().find("from Unit unit where unit.parentId="+parentId + " and unit.sekcio.id="+sekcioId);
		return list;
	}

}
